package com.it.sun.yuebike.base.controller;


import com.it.sun.yuebike.base.model.entity.UserEntity;
import com.it.sun.yuebike.base.service.UserService;
import com.it.sun.yuebike.framework.model.dto.Result;
import com.it.sun.yuebike.framework.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sunmannian
 * @since 2021-06-04
 */
@RestController
@RequestMapping("/user")
@Api(tags = "通用——用户服务")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{openid}")
    @ApiOperation(value = "根据openid获取用户信息")
    public Result<UserEntity> getByOpenid(@PathVariable String openid) {
        return userService.getByOpenid(openid);
    }

    @PostMapping()
    @ApiOperation("新增一个用户信息")
    public Result<UserEntity> saveUser(@RequestBody UserEntity userEntity) {
        return userService.save(userEntity) ? ResultUtils.success(userEntity) : ResultUtils.error("新增用户失败");
    }


}

